import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.InputMismatchException;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * ClassName: Test01
 * Package: PACKAGE_NAME
 * Description:
 * User: fzykd
 *
 * @Author: LQH
 * Date: 2023-08-26
 * Time: 9:40
 */

public class Test01 {

    public static void main(String[] args) {

        try {
            Scanner scanner = new Scanner(System.in);

            int num = scanner.nextInt();

            System.out.println(num);
        } catch (InputMismatchException e) {
            //输入类型不匹配的异常
            System.out.println("出现了InputMismatchException的异常");
        } catch (RuntimeException e) {
            //运行时候的异常 是父类 要放在最下main
            System.out.println("出现了RuntimeException的异常");
        }

        System.out.println("异常处理结束 代码继续执行");


        try {
            String str = "123";
            str = "abc";
            int i = Integer.parseInt(str);
            System.out.println(i);
        } catch (NumberFormatException e) {
            e.printStackTrace();
            System.out.println(e.getMessage());
        }

        System.out.println("程序结束");

        //在开发中 通常就是不显示的处理了
        //一旦程序执行 出现了运行时异常 那么就根据异常的提示信息 修改代码

        System.out.println("*************编译时候的异常*************");
        //就是必须要处理的了

        FileInputStream inputStream = null;
        try {
            File file = new File("D:/hello.txt");

            //肯能存在文件不存在异常
            inputStream = new FileInputStream(file);

            //可能出现空指针异常
            int data = inputStream.read();
            while (data != -1) {
                System.out.println(data);
                data = inputStream.read();
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (inputStream != null)
                    inputStream.close();
                //可以嵌套使用
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

}
